<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/SPLogin' }">homepage</el-breadcrumb-item>
      <el-breadcrumb-item>Edit</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 卡片视图区域 -->
    <!-- 用户去列表 -->
    <el-table :data="dudu" border stripe>
      <el-table-column type="index"></el-table-column>
      <el-table-column label="message" prop="message"></el-table-column>

      <el-table-column label="operation">
        <template>
          <!-- 修改按钮 -->
          <el-button type="primary" icon="el-icon-edit" size="mini" @click="showEditDialog()"></el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 修改用户对话框 -->
    <el-dialog title="Edit Librarian imformation" :visible.sync="editDialogVisible" width="50%" @close="editDialogclosed">
      <el-form :model="editForm" :rules="editFormRules" ref="editFormrRef" label-width="70px">
        <el-form-item label="name">
          <el-input v-model="queryInfo1.name" ></el-input>
        </el-form-item>
        <el-form-item label="pwd" >
          <el-input v-model="queryInfo1.password"></el-input>
        </el-form-item>
        <el-form-item label="rename">
          <el-input v-model="queryInfo1.nameRep"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">Cancel</el-button>
        <el-button type="primary" @click="editInfo">Confirm</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data () {
    return {
      // 获取数据
      booktype: [],
      dudu: [
        {
          message: 'Click the button on the right to select the Librarian information that needs to be edited'
        }
      ],
      // 修改用户对话框的显示与隐藏
      editDialogVisible: false,
      // 查询到的用户信息对象
      queryInfo: {
        name: 'test',
        password: 'test'
      },
      editForm: [],
      queryInfo1: {
        name: '',
        password: '',
        nameRep: ''
      }
    }
  },
  created () {
    this.getBookType()
  },
  methods: {
    async getBookType () {
      const { data: res } = await this.$http.get(
        'https://39.106.172.170/admin/login?name=test&password=test'
      )
      this.booktype = res.data
      // console.log(res)
    },
    // 编辑信息界面
    async showEditDialog () {
      // console.log()
      // const {data: res} = await this.$http.get(`https://118.178.190.4/searchBy?bookName=${book}&page=${this.queryInfo.page}`)
      // this.editForm = res.data
      // console.log(this.editForm.bookName)
      const { data: res } = await this.$http.get(
        'https://39.106.172.170/admin/login?name=test&password=test'
      )
      console.log(res)
      this.editDialogVisible = true
    },
    // 编辑信息
    async editInfo () {
      console.log(this.queryInfo1.name)
      console.log(this.queryInfo1.password)
      console.log(this.queryInfo1.nameRep)
      const {
        data: res
      } = await this.$http.put('https://39.106.172.170/admin/bookmanager?name=' + this.queryInfo1.name + '&password=' + this.queryInfo1.password + '&nameRep=' + this.queryInfo1.nameRep)
      console.log(res)
      this.editDialogVisible = false
      this.$message.success('Edit success！')
      
    },
    // 重置
    editDialogclosed () {
      this.$refs.editFormrRef.resetFields()
    },
    editFormRules () {}
  }
}
</script>
<style lang="less" scoped>
.el-breadcrumb {
  font-size: 20px;
}
.el-card {
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.15) !important;
}
.el-button {
  font-size: 20px;
}
.el-label{
  width: 500px
}
</style>
